CREATE PROCEDURE [dbo].[SeleccionarMateriasSemestresInferiores]
@id_Pensum int,
@numSemestre int,
@id_materia int
AS
BEGIN
	SET NOCOUNT ON;
	select m.id_Materia, m.nombreMateria, m.unidadesDeCredito, pm.semestre
	from Materia m, Pensum p, PensumMateria pm
	where pm.fk_id_materia = m.id_Materia
	and pm.fk_id_pensum = p.id_Pensum
	and p.id_pensum = @id_Pensum
	and pm.semestre < @numSemestre 
	and m.id_materia not in (select pp.fk_materia_prelacion
								from Prelacion pp
								where pp.fk_materia_actual = @id_materia and pp.fk_pensum = @id_Pensum)
	order by pm.semestre
	desc
	
	
END;